package com.cssl.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig2{
    public static final String ORDER_GOOD_QUEUE = "order_goods_queue";//订单商品队列
    public static final String ORDER_GOOD_EXCHANGE = "order_goods_exchange";//订单商品交换机
    public static final String ORDER_GOODS_ROUTINGKEY = "order_goods_routingkey";//创建订单商品路由

    //序列化jackson
    @Bean
    public MessageConverter jackson2JsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    //订单商品
    @Bean
    public Queue orderQueue(){
        return new Queue(ORDER_GOOD_QUEUE,true,false,true);
    }

    @Bean
    public Exchange orderExchange(){
        return ExchangeBuilder.directExchange(ORDER_GOOD_EXCHANGE).durable(true).build();
    }

    @Bean
    public Binding orderBind(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(ORDER_GOODS_ROUTINGKEY).noargs();
    }
}
